package io.renren.minimito.service.impl;

import io.renren.minimito.entity.SqActivityEntity;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.minimito.dao.SqTopicDao;
import io.renren.minimito.entity.SqTopicEntity;
import io.renren.minimito.service.SqTopicService;
import org.springframework.util.StringUtils;


@Service("sqTopicService")
public class SqTopicServiceImpl extends ServiceImpl<SqTopicDao, SqTopicEntity> implements SqTopicService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SqTopicEntity> page = this.page(
                new Query<SqTopicEntity>().getPage(params),
                new QueryWrapper<SqTopicEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
        QueryWrapper<SqTopicEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.and((w)->{
                w.eq("id",key).or().like("topic_title",key)
                        .or().like("dongtai_content",key)
                        .or().like("local_city",key)
                        .or().like("local_detail",key)
                        .or().like("tags",key);
            });
        }
        IPage<SqTopicEntity> page = this.page(
                new Query<SqTopicEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}